<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var arr = [12, 3, 343, 43, 21, 4, 1, 56]
      //   var newArr = []
      var t = 0

      for (var j = 0; j < arr.length - 1; j++) {
        for (var i = 0; i < arr.length - 1 - j; i++) {
          if (arr[i] >= arr[i + 1]) {
            //   加减法交换位置有
            t = arr[i] + arr[i + 1]
            arr[i] = t - arr[i]
            arr[i + 1] = t - arr[i]
          }
        }
      }
      console.log(arr)
      //   console.log(newArr)
    </script>
  </body>
</html>
